/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.muni.fi.pv168.reminder.swing.workers;

import cz.muni.fi.pv168.reminder.entities.Worker;
import cz.muni.fi.pv168.reminder.managers.WorkerManager;
import cz.muni.fi.pv168.reminder.managers.implementation.WorkerManagerImpl;
import cz.muni.fi.pv168.reminder.swing.DialogMainWorker;
import cz.muni.fi.pv168.reminder.swing.FrameMainWindow;
import javax.swing.SwingWorker;

/**
 *
 * @author Adic
 */
public class UpdateWorkerSwingWorker extends SwingWorker<Class<Void>, Void> {
    private final Worker worker;
    DialogMainWorker.TableWorkerModel model;

    public UpdateWorkerSwingWorker(Worker worker, DialogMainWorker.TableWorkerModel model) {
        this.worker = worker;
        this.model = model;
    }

    @Override
    protected Class<Void> doInBackground() throws Exception {
        WorkerManager workerManager = new WorkerManagerImpl();
        workerManager.setDataSource(FrameMainWindow.getDataSource());
        workerManager.updatePerson(worker);
        return Void.TYPE;
    }

    @Override
    protected void done() {
        super.done();
        model.reload();
    }
    
}
